-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid no-op when truncating a vector to same size. #78884
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cramertj (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
📌 Commit 181d811 has been approved by |
@bors r- Oops, didn't notice that CI is failing. It looks like this is adding a new branch in https://github.com/rust-lang/rust/blob/master/src/test/codegen/vec-clear.rs -- probably it was previously inlining the |
The linked test(?) doesn't look like it has any kind of assertion and I don't know what |
That's a codegen test using FileCheck, https://llvm.org/docs/CommandGuide/FileCheck.html#tutorial It'll need either changing the test or changing the code so that |
FWIW this was previously attempted in #74172 |
Fixes #76089. |
@flotts Ping from triage, would you mind addressing the comments above? If you need some help, you can visit the rust-lang.zulipchat.com and seek for some help there. Thanks! |
I've been pretty swamped between school and work, I didn't expect this problem to be so complicated to solve, and I don't want to make changes to tests without sufficient understanding of the implications of those changes. Frankly, it makes no sense to me that there's a new branch as a result of this code. I would recommend someone simply close this and give up for now or something. Maybe another time, if someone else doesn't fix it first. It clearly isn't a proper solution to this issue :P |
For anyone else who arrives and looks at this: this can happen because the old code, after inlining, resulted in |
I noticed that
Vec::truncate()
will actually execute unnecessary operations if the targetlen
is the same as the currentlen
, even though it should do nothing. The method already checks whether the targetlen
is greater than the currentlen
, so I simply changed this check to a>=
and updated the wording of the associated doc comment to reflect this.While the lack of the
=
incurs a nearly negligible amount of unnecessary overhead, this does happen whenclear()
ing an empty vector or string, which happens fairly commonly.